package main

import (
	"fmt"
	"ordersystem/config"
	"ordersystem/database"
	"ordersystem/router"
	"ordersystem/util"

	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/cors"
)

func main() {
	// // 初始化数据库连接池
	if err := database.InitMysqlConnection(); err != nil {
		fmt.Println("数据库连接初始化异常！")
		return
	}

	app := fiber.New(fiber.Config{
		ErrorHandler: util.FiberErrorHandler,
	})

	// set cross domain credentials
	app.Use(cors.New(cors.Config{
		AllowOrigins:     "http://127.0.0.1:8080",
		AllowHeaders:     "Origin, Content-Type, Accept",
		AllowCredentials: true,
	}))

	router.Setup(app)
	app.Listen(config.APP_URL)

}
